package com.paradise.ytj.activity;

import android.app.Application;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.Log;

import com.paradise.ytj.R;
import com.paradise.ytj.bean.Constant;
import com.paradise.ytj.helper.CrashHandler;
import com.paradise.ytj.utils.SpUtils;
import com.paradise.api.FacePhone;
import com.paradise.api.FacephonePreferences;

import org.linphone.core.LinphoneCore;
import org.linphone.mediastream.video.capture.MediaConfigure;

import java.util.Locale;


/**
 * Created by Administrator on 2017/9/7 0007.
 * 这是机顶盒版本编码用0，
 * 最新版本3.3 稳定版
 */
public class ParaApplication extends Application {

    private LinphoneCore mLc;
    private int anInt;

    @Override
    public void onCreate() {
        super.onCreate();
        CrashHandler.getInstance().init(this);
        initVar();
        initConfig();
    }

    private void initVar() {

        //encode 1:CPU硬编（普通摄像头）  5:专业硬编（专业摄像头）
        //decode 0:软解  1:硬解
        int i = FacePhone.instance().initPhone(getApplicationContext(), R.raw.oldphone_mono,
                R.raw.ringback, R.raw.toy_mono, R.raw.incoming_chat,
                R.raw.lpconfig, R.raw.rootca, null, MediaConfigure.DEVICE_WEIDU_YTJ);
        FacephonePreferences.instance().setDebugEnabled(true);
        FacePhone.instance().getmLc().setVideoDevice(0);


        //默认息屏时间
        anInt = SpUtils.getInt(getApplicationContext(), Constant.LOCK_NAME, Constant.LOCK_DEFAULT);

        // 初始化LinphoneCore
        mLc = FacePhone.instance().getmLc();

    }

    private void initConfig() {

        //设置默认配置
        FacephonePreferences.instance().setPreferredVideoFps(30);
        FacephonePreferences.instance().setCodecBitrateLimit(128);
        FacephonePreferences.instance().setVideoBitrate(2048);

        mLc.setAdaptiveRateAlgorithm(LinphoneCore.AdaptiveRateAlgorithm.Simple);
        mLc.enableAdaptiveRateControl(true);
        FacePhone.instance().getmLc().setMaxCalls(1);

        //设置默认息屏时间
        Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, anInt * 1000 * 60);
    }

}
